Online-Academy

Look, Read, Understand, Apply

Menu

Including content of another file in a JSP file

Including content of another file in a JSP file

The JSP include directive is used to include content of another source file into a JSP file. The content of file which includes external file is merged with content of the external file. The general syntax for including content of another file is as follows:

Parameters can also be passed to the included file.

Example for including content of another file in the jsp page

Here address.jsp file is created. It displays address and email of user that are provided to it. File named "including.jsp" includes the "address.jsp file", passes required parameter to it.

address.jsp

<%
out.println("<p>Address: "+request.getParameter("address")+"</p>");
out.println("<p>Email: "+request.getParameter("email")+"</p>");
%>

including.jsp

<html>
<body>
<p>This is first paragraph</p>
<p>This is second paragraph</p>
<p>
This paragraph is from another file.
<p>
<jsp:include page="address.jsp">
<jsp:param name="address" value="Baneshwor"/>
<jsp:param name="email" value="dinesh8np@gmail.com"/>
</jsp:include>
</p>
</p>
</body>
</html>